package com.geticsen.leetcode;
//https://leetcode-cn.com/problems/reverse-linked-list/
public class Solution_206 {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode listNode = reverseList(head.next, head);
        head.next = null;
        return listNode;
    }

    private ListNode reverseList(ListNode node, ListNode pre) {
        if (node != null && node.next == null) {
            node.next = pre;
            return node;
        }
        if (node != null) {
            ListNode listNode = reverseList(node.next, node);
            node.next = pre;
            return listNode;
        }
        return null;
    }
}
